package com.ql.controller;

import com.ql.domain.request.SelectTemplate;
import com.ql.service.SelectTemplateService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/template")
public class SelectTemplateController {
    @Autowired
    SelectTemplateService selectTemplateService;

    @RequestMapping("/findAllTemplate.do")
    @ResponseBody
    public List<SelectTemplate> getTemplateAll(String id) {
        return selectTemplateService.findAll(id);
    }

    @RequestMapping("/findOneTemplate.do")
    @ResponseBody
    public SelectTemplate getTemplate(String selectValue, String userId) {
        if (StringUtils.isEmpty(selectValue)&&StringUtils.isEmpty(userId)) {
            return new SelectTemplate();
        }
        return selectTemplateService.findTemplate(selectValue,userId);
    }

    @RequestMapping("/updateTemplate.do")
    @ResponseBody
    public int save(SelectTemplate selectTemplate) {
        System.out.println(selectTemplate);
        return selectTemplateService.update(selectTemplate);

    }

    @RequestMapping("/addTemplate.do")
    @ResponseBody
    public int add(SelectTemplate selectTemplate) {
        return selectTemplateService.add(selectTemplate);
    }

    @RequestMapping("/deleteTemplate.do")
    @ResponseBody
    public int del(SelectTemplate selectTemplate) {
        return selectTemplateService.del(selectTemplate);
    }
}
